import socket
import time
class tcp_demo():
    #实例化socket-建立连接-传送数据-关闭连接
    def tcp_test(self):
        soc = socket.socket(family=socket.AF_INET,type=socket.SOCK_STREAM)
        soc.connect(("192.168.8.8",554))
        soc.send("YYYYYY".encode("GB2312"))
        soc.close()
    def udp_test(self):
        soc = socket.socket(family=socket.AF_INET,type=socket.SOCK_DGRAM)
        soc.connect(("192.168.8.129",2425))
        pacaketID = str(time.time())
        name = 'YY'
        host = "Y-Y"
        command = str(0x00000020)
        content = "你好啊，我是帅强"
        msg = "1.0:"+pacaketID+":"+name+":"+host+":"+command+":"+content
        soc.send(msg.encode("GB2312"))
        soc.close()
if __name__ == "__main__":
    # tcp_demo().tcp_test()
    tcp_demo().udp_test()